Allow unsetting the title by setting to NULL. Move docs inline. Update the
authorOwen Taylor <otaylor@redhat.com>
Thu, 27 Dec 2001 20:22:16 +0000 (20:22 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Thu, 27 Dec 2001 20:22:16 +0000 (20:22 +0000)
Thu Dec 27 15:13:44 2001  Owen Taylor  <otaylor@redhat.com>

* gtk/gtkmenu.c (gtk_menu_set_title): Allow unsetting
the title by setting to NULL. Move docs inline.
Update the title if the tearoff window already
exists. Code cleanup. (Fixes #65190, reported by
Vitaly Tishkov.)

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
docs/reference/gtk/tmpl/gtkmenu.sgml
gtk/gtkmenu.c

index 5e160d15c1c67f4ec02d4063f725190c1a0d8b12..2d828a0f1bcffe87812639c41035ce5911ab9443 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Thu Dec 27 15:13:44 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkmenu.c (gtk_menu_set_title): Allow unsetting
+       the title by setting to NULL. Move docs inline. 
+       Update the title if the tearoff window already
+       exists. Code cleanup. (Fixes #65190, reported by
+       Vitaly Tishkov.)
+
 Thu Dec 27 14:04:22 2001  Owen Taylor  <otaylor@redhat.com>
 
        * gtk/gtksocket.c (gtk_socket_key_press_event): 
index 5e160d15c1c67f4ec02d4063f725190c1a0d8b12..2d828a0f1bcffe87812639c41035ce5911ab9443 100644 (file)
@@ -1,3 +1,11 @@
+Thu Dec 27 15:13:44 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkmenu.c (gtk_menu_set_title): Allow unsetting
+       the title by setting to NULL. Move docs inline. 
+       Update the title if the tearoff window already
+       exists. Code cleanup. (Fixes #65190, reported by
+       Vitaly Tishkov.)
+
 Thu Dec 27 14:04:22 2001  Owen Taylor  <otaylor@redhat.com>
 
        * gtk/gtksocket.c (gtk_socket_key_press_event): 
index 5e160d15c1c67f4ec02d4063f725190c1a0d8b12..2d828a0f1bcffe87812639c41035ce5911ab9443 100644 (file)
@@ -1,3 +1,11 @@
+Thu Dec 27 15:13:44 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkmenu.c (gtk_menu_set_title): Allow unsetting
+       the title by setting to NULL. Move docs inline. 
+       Update the title if the tearoff window already
+       exists. Code cleanup. (Fixes #65190, reported by
+       Vitaly Tishkov.)
+
 Thu Dec 27 14:04:22 2001  Owen Taylor  <otaylor@redhat.com>
 
        * gtk/gtksocket.c (gtk_socket_key_press_event): 
index 5e160d15c1c67f4ec02d4063f725190c1a0d8b12..2d828a0f1bcffe87812639c41035ce5911ab9443 100644 (file)
@@ -1,3 +1,11 @@
+Thu Dec 27 15:13:44 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkmenu.c (gtk_menu_set_title): Allow unsetting
+       the title by setting to NULL. Move docs inline. 
+       Update the title if the tearoff window already
+       exists. Code cleanup. (Fixes #65190, reported by
+       Vitaly Tishkov.)
+
 Thu Dec 27 14:04:22 2001  Owen Taylor  <otaylor@redhat.com>
 
        * gtk/gtksocket.c (gtk_socket_key_press_event): 
index 5e160d15c1c67f4ec02d4063f725190c1a0d8b12..2d828a0f1bcffe87812639c41035ce5911ab9443 100644 (file)
@@ -1,3 +1,11 @@
+Thu Dec 27 15:13:44 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkmenu.c (gtk_menu_set_title): Allow unsetting
+       the title by setting to NULL. Move docs inline. 
+       Update the title if the tearoff window already
+       exists. Code cleanup. (Fixes #65190, reported by
+       Vitaly Tishkov.)
+
 Thu Dec 27 14:04:22 2001  Owen Taylor  <otaylor@redhat.com>
 
        * gtk/gtksocket.c (gtk_socket_key_press_event): 
index 5e160d15c1c67f4ec02d4063f725190c1a0d8b12..2d828a0f1bcffe87812639c41035ce5911ab9443 100644 (file)
@@ -1,3 +1,11 @@
+Thu Dec 27 15:13:44 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkmenu.c (gtk_menu_set_title): Allow unsetting
+       the title by setting to NULL. Move docs inline. 
+       Update the title if the tearoff window already
+       exists. Code cleanup. (Fixes #65190, reported by
+       Vitaly Tishkov.)
+
 Thu Dec 27 14:04:22 2001  Owen Taylor  <otaylor@redhat.com>
 
        * gtk/gtksocket.c (gtk_socket_key_press_event): 
index 5e160d15c1c67f4ec02d4063f725190c1a0d8b12..2d828a0f1bcffe87812639c41035ce5911ab9443 100644 (file)
@@ -1,3 +1,11 @@
+Thu Dec 27 15:13:44 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkmenu.c (gtk_menu_set_title): Allow unsetting
+       the title by setting to NULL. Move docs inline. 
+       Update the title if the tearoff window already
+       exists. Code cleanup. (Fixes #65190, reported by
+       Vitaly Tishkov.)
+
 Thu Dec 27 14:04:22 2001  Owen Taylor  <otaylor@redhat.com>
 
        * gtk/gtksocket.c (gtk_socket_key_press_event): 
index 14f94d048907dd296b760a51c4e4e8f4f90a1a60..c8e028f2331428b159535311f3bed29a745e3157 100644 (file)
@@ -192,12 +192,10 @@ See gtk_menu_set_accel_group().
 
 <!-- ##### FUNCTION gtk_menu_set_title ##### -->
 <para>
-Sets the title string for the menu.  The title is displayed when the menu
-is shown as a tearoff menu.
 </para>
 
-@menu: a #GtkMenu.
-@title: a string containing the title for the menu.
+@menu:
+@title: 
 
 
 <!-- ##### FUNCTION gtk_menu_get_tearoff_state ##### -->
index f2b30b99f6dc7a73264cc07b2e2b57815f66722c..7041510f9a76443d2c943ad1c6ea1ab690fd1114 100644 (file)
@@ -134,6 +134,8 @@ static void gtk_menu_reparent       (GtkMenu           *menu,
 static void gtk_menu_remove         (GtkContainer      *menu,
                                     GtkWidget         *widget);
 
+static void gtk_menu_update_title   (GtkMenu           *menu);
+
 static void _gtk_menu_refresh_accel_paths (GtkMenu *menu,
                                           gboolean group_changed);
 
@@ -288,8 +290,7 @@ gtk_menu_get_property (GObject     *object,
   switch (prop_id)
     {
     case PROP_TEAROFF_TITLE:
-      g_value_set_string (value, gtk_object_get_data (GTK_OBJECT (menu), 
-                                                     "gtk-menu-title"));
+      g_value_set_string (value, gtk_menu_get_title (menu));
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -464,6 +465,9 @@ gtk_menu_attach_to_widget (GtkMenu         *menu,
   /* we don't need to set the style here, since
    * we are a toplevel widget.
    */
+
+  /* Fallback title for menu comes from attach widget */
+  gtk_menu_update_title (menu);
 }
 
 GtkWidget*
@@ -503,6 +507,9 @@ gtk_menu_detach (GtkMenu *menu)
   
   g_free (data);
   
+  /* Fallback title for menu comes from attach widget */
+  gtk_menu_update_title (menu);
+
   gtk_widget_unref (GTK_WIDGET (menu));
 }
 
@@ -971,6 +978,30 @@ gtk_menu_set_tearoff_hints (GtkMenu *menu,
                                 GDK_HINT_MAX_SIZE|GDK_HINT_MIN_SIZE);
 }
 
+static void
+gtk_menu_update_title (GtkMenu *menu)
+{
+  if (menu->tearoff_window)
+    {
+      const gchar *title;
+      GtkWidget *attach_widget;
+
+      title = gtk_menu_get_title (menu);
+      if (!title)
+       {
+         attach_widget = gtk_menu_get_attach_widget (menu);
+         if (GTK_IS_MENU_ITEM (attach_widget))
+           {
+             GtkWidget *child = GTK_BIN (attach_widget)->child;
+             if (GTK_IS_LABEL (child))
+               title = gtk_label_get_text (GTK_LABEL (child));
+           }
+       }
+      
+      if (title)
+       gtk_window_set_title (GTK_WINDOW (menu->tearoff_window), title);
+    }
+}
 
 void       
 gtk_menu_set_tearoff_state (GtkMenu  *menu,
@@ -992,9 +1023,6 @@ gtk_menu_set_tearoff_state (GtkMenu  *menu,
 
          if (!menu->tearoff_window)
            {
-             GtkWidget *attach_widget;
-             gchar *title;
-             
              menu->tearoff_window = g_object_connect (gtk_widget_new (GTK_TYPE_WINDOW,
                                                                       "type", GTK_WINDOW_TOPLEVEL,
                                                                       NULL),
@@ -1008,30 +1036,17 @@ gtk_menu_set_tearoff_state (GtkMenu  *menu,
                                  "event",
                                  GTK_SIGNAL_FUNC (gtk_menu_window_event), 
                                  GTK_OBJECT (menu));
-             gtk_widget_realize (menu->tearoff_window);
-             
-             title = gtk_object_get_data (GTK_OBJECT (menu), "gtk-menu-title");
-             if (!title)
-               {
-                 attach_widget = gtk_menu_get_attach_widget (menu);
-                 if (GTK_IS_MENU_ITEM (attach_widget))
-                   {
-                     GtkWidget *child = GTK_BIN (attach_widget)->child;
-                     if (GTK_IS_LABEL (child))
-                       gtk_label_get (GTK_LABEL (child), &title);
-                   }
-               }
 
-             if (title)
-               gdk_window_set_title (menu->tearoff_window->window, title);
+             gtk_menu_update_title (menu);
 
+             gtk_widget_realize (menu->tearoff_window);
+             
              gdk_window_set_decorations (menu->tearoff_window->window, 
                                          GDK_DECOR_ALL |
                                          GDK_DECOR_RESIZEH |
                                          GDK_DECOR_MINIMIZE |
                                          GDK_DECOR_MAXIMIZE);
-             gtk_window_set_policy (GTK_WINDOW (menu->tearoff_window),
-                                    FALSE, FALSE, TRUE);
+             gtk_window_set_resizable (GTK_WINDOW (menu->tearoff_window), FALSE);
 
              menu->tearoff_hbox = gtk_hbox_new (FALSE, FALSE);
              gtk_container_add (GTK_CONTAINER (menu->tearoff_window), menu->tearoff_hbox);
@@ -1103,14 +1118,27 @@ gtk_menu_get_tearoff_state (GtkMenu *menu)
   return menu->torn_off;
 }
 
+/**
+ * gtk_menu_set_title:
+ * @menu: a #GtkMenu
+ * @title: a string containing the title for the menu.
+ * 
+ * Sets the title string for the menu.  The title is displayed when the menu
+ * is shown as a tearoff menu.
+ **/
 void       
 gtk_menu_set_title (GtkMenu     *menu,
                    const gchar *title)
 {
   g_return_if_fail (GTK_IS_MENU (menu));
 
-  gtk_object_set_data_full (GTK_OBJECT (menu), "gtk-menu-title",
+  if (title)
+    g_object_set_data_full (G_OBJECT (menu), "gtk-menu-title",
                            g_strdup (title), (GtkDestroyNotify) g_free);
+  else
+    g_object_set_data (G_OBJECT (menu), "gtk-menu-title", NULL);
+    
+  gtk_menu_update_title (menu);
   g_object_notify (G_OBJECT (menu), "tearoff_title");
 }